home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 March: Reference Library / Dev.CD Mar 97 RL.toast / mac / Technical Documentation / develop / develop Issue 23 / develop Issue 23 code / ProjectDrag 1.1b8.sea / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / ProjectDrag.c / ProjectDrag.c
Encoding:
C/C++ Source or Header  |  1995-07-11  |  4.9 KB  |  253 lines  |  [TEXT/MPS ]

  1. /* ProjectDrag.c: Main application code for all applets in ProjectDrag
  2.  * Mutated from DropShell.c.
  3.  *
  4.  * A set of applets for drag and drop source control by Tim Maroney.
  5.  * See develop, issue 23 for details.
  6.  *
  7.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  8.  * and using the MoreFiles utilities by Jim Luther.
  9.  *
  10.  * This software is free, but don't modify and redistribute it without
  11.  * changing the status window to indicate your name and your changes!
  12.  */
  13.  
  14.  
  15. #ifndef __MWERKS__
  16. #include <Desk.h>
  17. #include <Dialogs.h>
  18. #include <DiskInit.h>
  19. #include <Errors.h>
  20. #include <Files.h>
  21. #include <Fonts.h>
  22. #include <Memory.h>
  23. #include <Menus.h>
  24. #include <StandardFile.h>
  25. #include <TextEdit.h>
  26. #include <Types.h>
  27. #include <Windows.h>
  28. #endif
  29.  
  30. #include "DSGlobals.h"
  31. #include "DSUserProcs.h"
  32. #include "DSAppleEvents.h"
  33.  
  34. #include "DropShell.h"
  35. #include "PDUtilities.h"
  36. #include "PDDialogs.h"
  37. #include "TasksAndErrors.h"
  38.  
  39.  
  40.  
  41. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  42. EventRecord    gEvent;
  43. MenuHandle    gAppleMenu, gFileMenu;
  44.  
  45. #ifdef MPW
  46. extern void _DataInit();    
  47. #endif
  48.  
  49.  
  50. extern void DoFileMenu(short itemID);
  51.  
  52.  
  53. #pragma segment Initialize
  54. void InitToolbox (void) 
  55. {
  56.  
  57. #ifdef MPW
  58.     UnloadSeg ((Ptr) _DataInit );
  59. #endif
  60.  
  61.     InitGraf ( &qd.thePort );
  62.     InitFonts ();
  63.     InitWindows ();
  64.     InitMenus ();
  65.     TEInit ();
  66.     InitDialogs (NULL);        // use of ResumeProcs no longer approved by Apple
  67.     InitCursor ();
  68.     FlushEvents ( everyEvent, 0 );
  69.     
  70.     // how about some memory fun! Two should be enough!
  71.     MoreMasters ();
  72.     MoreMasters ();
  73.     
  74.     MaxApplZone();
  75.     }
  76.  
  77. /*
  78.     Let's setup those global variables that the DropShell uses.
  79.     
  80.     If you add any globals for your own use,
  81.     init them in the InitUserGlobals routine in DSUserProcs.c
  82. */
  83. #pragma segment Initialize
  84. Boolean InitGlobals (void) 
  85. {
  86.     long aLong;
  87.  
  88.     gDone            = false;
  89.     gOApped            = false;    // probably not since users are supposed to DROP things!
  90.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  91.  
  92.     return(InitUserGlobals());    // call the user proc
  93. }
  94.  
  95. /*
  96.     Again, nothing fancy.  Just setting up the menus.
  97.     
  98.     If you add any menus to your DropBox - insert them here!
  99. */
  100. #pragma segment Initialize
  101. void SetUpMenus (void) {
  102.  
  103.     gAppleMenu = GetMenu ( kAppleNum );
  104.     AddResMenu ( gAppleMenu, 'DRVR' );
  105.     InsertMenu ( gAppleMenu, 0 );
  106.  
  107.     gFileMenu = GetMenu ( kFileNum );
  108.     InsertMenu ( gFileMenu, 0 );
  109.     DrawMenuBar ();
  110. }
  111.  
  112.  
  113. /*    --------------- Standard Event Handling routines ---------------------- */
  114. #pragma segment Main
  115. void ShowAbout () {
  116.     (void) Alert ( 128, NULL );
  117.     }
  118.  
  119.  
  120. #pragma segment Main
  121. void DoMenu ( long retVal ) {
  122.     short    menuID, itemID;
  123.     Str255    itemStr;
  124.  
  125.     menuID = HiWord ( retVal );
  126.     itemID = LoWord ( retVal );
  127.     
  128.     switch ( menuID ) {
  129.         case kAppleNum:
  130.             if ( itemID == 1 )
  131.             {
  132.                 ShowAbout ();    /*    Show the about box */
  133.             }
  134.             else
  135.             {
  136.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  137.                 OpenDeskAcc(itemStr);
  138.             }
  139.             break;
  140.             
  141.         case kFileNum:
  142.             DoFileMenu(itemID);
  143.             break;
  144.         
  145.         default:
  146.             break;
  147.             
  148.         }
  149.     HiliteMenu(0);        // turn it off!
  150.     }
  151.  
  152.  
  153. #pragma segment Main
  154. void DoMouseDown ( EventRecord *curEvent ) {
  155.     WindowPtr    whichWindow;
  156.     short        whichPart;
  157.  
  158.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  159.     switch ( whichPart ) {
  160.         case inMenuBar:
  161.             DoMenu ( MenuSelect ( curEvent->where ));
  162.             break;
  163.         
  164.         case inSysWindow:
  165.             SystemClick ( curEvent, whichWindow );
  166.             break;
  167.         
  168.         case inDrag:
  169.             {
  170.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  171.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  172.             }
  173.             break;
  174.         }
  175.     }
  176.  
  177.  
  178. #pragma segment Main
  179. void DoKeyDown ( EventRecord *curEvent ) {
  180.     if ( curEvent->modifiers & cmdKey )
  181.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  182.     }
  183.  
  184.  
  185. #pragma segment Main
  186. static Boolean IsCommandKey(EventRecord *event) {
  187.     return (event->what == keyDown) && ((event->modifiers & cmdKey) != 0);
  188.     }
  189.  
  190. #pragma segment Main
  191. void main ( ) 
  192. {
  193.     InitToolbox ();
  194.     if ( !InitGlobals () ) return;    
  195.     if ( !gHasAppleEvents ) {
  196.         ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  197.         DisposeUserGlobals();    // call the userproc to clean itself up
  198.         return;
  199.     }
  200.     InitAEVTStuff ();
  201.     SetUpMenus ();
  202.     
  203.     while ( !gDone ) {
  204.         gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  205.         if ( !gWasEvent )
  206.         {
  207.             Str255 s;
  208.             GetIndString(s, kProjectDragStrings, kIdleStatus);
  209.             SetStatusMessage(s);
  210.             continue;
  211.         }
  212.         
  213.         /* handle dialog updating */
  214.         if (!IsCommandKey(&gEvent) && IsDialogEvent(&gEvent)) {
  215.             DialogPtr dialog;
  216.             short itemHit;
  217.             
  218.             DialogSelect(&gEvent, &dialog, &itemHit);
  219.             continue;
  220.         }
  221.         
  222.         switch ( gEvent.what ) {
  223.         case kHighLevelEvent:
  224.             DoHighLevelEvent ( &gEvent );
  225.             break;
  226.             
  227.         case mouseDown:
  228.             DoMouseDown ( &gEvent );
  229.             break;
  230.             
  231.         case keyDown:
  232.         case autoKey:
  233.             DoKeyDown ( &gEvent );
  234.             break;
  235.  
  236.         case diskEvt:
  237.             if (HiWord(gEvent.message)) {
  238.                 Point diskInitPt;
  239.                 
  240.                 diskInitPt.v = diskInitPt.h = 100;
  241.                 DILoad();
  242.                 DIBadMount(diskInitPt, gEvent.message);
  243.                 DIUnload();
  244.             }
  245.             break;
  246.         }
  247.         
  248.         PopAllTasks();
  249.     }
  250.     
  251.     DisposeUserGlobals();    // call the userproc to clean itself up
  252. }
  253.